package com.example.bean;

import com.alibaba.fastjson.JSONArray;
import lombok.Data;
import lombok.ToString;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.List;

import static com.example.spring_xx_u_market.SpringXxUMarketApplication.jdbcTemplate;

@Data
@ToString
public class OrderV {
    private int error_code;
    private JSONArray buyer_order_list;
    private JSONArray seller_order_list;

    public OrderV(String uid) {
        error_code = 0;
        buyer_order_list = new JSONArray();
        seller_order_list = new JSONArray();

        List<OrderInfoV> query = jdbcTemplate.query("select order_info.goods_id,order_id,plan_time,fact_time,final_price," +
                        "order_info.trade_type,name,image_urls,detail_info " +
                        "from second_hand.order_info,second_hand.uid,second_hand.goods_info " +
                        "where uid.uid=? and uid.account=order_info.seller_account " +
                        "and order_info.goods_id=goods_info.goods_id;",
                new BeanPropertyRowMapper<>(OrderInfoV.class), uid);
        seller_order_list.addAll(query);

        query = jdbcTemplate.query("select order_info.goods_id,order_id,plan_time,fact_time,final_price," +
                        "order_info.trade_type,name,image_urls,detail_info " +
                        "from second_hand.order_info,second_hand.uid,second_hand.goods_info " +
                        "where uid.uid=? and uid.account=order_info.buyer_account " +
                        "and order_info.goods_id=goods_info.goods_id;",
                new BeanPropertyRowMapper<>(OrderInfoV.class), uid);
        buyer_order_list.addAll(query);
    }
}
